package com.srd.phone.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.shengrongdai.srd.R;
import com.srd.phone.dialog.MoneyTrustDialog;
import com.srd.phone.mvp.presenters.BasePresenter;
import com.srd.phone.utils.Constants;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 注册成功
 */
public class RegisterSuccessActivity extends BaseActivity {

    private String url = Constants.BASEURL + "huifuUserRegisterApp/userRegisterReady";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register_success);
        initView();
        initData();
    }

    @Override
    public void initView() {
        super.initView();
        tv_common_title.setText("注册");
        dialog();
    }

    @Override
    public void initData() {
        presenter = new BasePresenter(requestQueue, this);
        setUrlArrs(url);
    }

    @Override
    public void returnData(String tag, String data) {
        super.returnData(tag, data);
        cancelWaitingDialog();
        try {
            JSONObject jsonObject = new JSONObject(data);
            String jsonData = jsonObject.optString("data");
            Intent intent = new Intent(mContext, CarouselActivity.class);
            intent.putExtra("url", jsonData);
            startActivity(intent);
            finish();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    private MoneyTrustDialog trustDialog;

    private void dialog() {
        trustDialog = new MoneyTrustDialog(mContext, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                trustDialog.dismiss();
            }
        }, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                trustDialog.dismiss();
                showWaitingDialog();
                presenter.requestPostData(url);
            }
        });
        trustDialog.show();
    }

}
